package com.atguigu.utils;

import lombok.SneakyThrows;
import org.apache.flink.streaming.api.windowing.windows.TimeWindow;
import org.apache.flink.util.Collector;

import java.lang.reflect.Field;


public class WindowFunctionUtil {

    @SneakyThrows
    public static <T> void set(Iterable<T> input, TimeWindow window, Collector<T> out){
        T next = input.iterator().next();

        Class<?> nextClass = next.getClass();

        Field ts = nextClass.getDeclaredField("ts");
        ts.setAccessible(true);
        ts.set(next,System.currentTimeMillis());

        Field stt = nextClass.getDeclaredField("stt");
        stt.setAccessible(true);
        stt.set(next,DateFormatUtil.toYmdHms(window.getStart()));

        Field edt = nextClass.getDeclaredField("edt");
        edt.setAccessible(true);
        edt.set(next,DateFormatUtil.toYmdHms(window.getEnd()));

        out.collect(next);


        //BeanUtils.setProperty(next,"ts",System.currentTimeMillis());
        //BeanUtils.setProperty(next,"stt",DateFormatUtil.toYmdHms(window.getStart()));
        //BeanUtils.setProperty(next,"edt",DateFormatUtil.toYmdHms(window.getEnd()));

    }
}
